{% extends 'mobile/base.html' %}

{% from "includes/common_macros.html" import list_view_item %}
{% from "wiki/includes/document_macros.html" import contributor_list, document_title, document_messages, document_content  %}
{% from "wiki/mobile/includes/document_macros.html" import vote_form with context %}

{% set title = _('{t} | {c}')|f(t=document.title, c=document.get_category_display()) %}
{% set headline = title %}

{% if products.all()[0] and product_topics.all()[0] %}
  {% set return_url = url('products.documents', product_slug=products.all()[0].slug, topic_slug=product_topics.all()[0].slug) %}
{% elif products.all()[0] %}
  {% set return_url = url('products.product', slug=products.all()[0].slug) %}
{% else %}
  {% set return_url = url('products') %}
{% endif %}

{% set show_search = 'bottom' %}
{% set include_showfor = True %}
{% set styles = ('mobile-wiki',) %}
{% set classes = 'document' %}
{% set scripts = ('mobile-wiki',) %}
{% set canonical_url = canonicalize(model_url=document.get_absolute_url()) %}
{% if document.is_template or document.is_archived %}
  {% set meta = (('robots', 'noindex'),) %}
{% endif %}

{% if document.parent %}
  {# If there is a parent doc, use it's URL for switching locales. #}
  {% set localizable_url = url('wiki.document', document.parent.slug, locale=settings.WIKI_DEFAULT_LANGUAGE) %}
{% endif %}

{% block content %}
  {% if breadcrumb_items[1] %}
    <div class="filter-bar">
      <a class="return-link" href="{{ breadcrumb_items[-2][0] }}">{{ breadcrumb_items[-2][1] }}</a>
    </div>
  {% endif %}
  <article id="wiki-doc">
    {{ document_title(document) }}
    {{ document_messages(document, redirected_from) }}
    {{ document_content(document, fallback_reason, request, settings, document_css_class, any_localizable_revision, full_locale_name) }}

    {% set share_link = document.share_link or (document.parent and document.parent.share_link) %}
    {% if share_link %}
      <p class="share-link">
        <br/>
        {% set link='<a href="' + share_link + '">' + share_link + '</a>' %}
        {{ _('Share this article: {link}')|f(link=link|safe) }}
      </p>
    {% endif %}

    {% if not waffle.switch('hide-voting') %}
      {{ vote_form(document, source='mobile') }}
    {% endif %}

    {{ contributor_list(contributors) }}

    {% if document.current_revision %}
      <div class="last_update">
        <p>
          {{ _('Last Update: {date}')|f(date=document.current_revision.created.date()) }}
        </p>
      </div>
    {% endif %}

    {% if document.related_documents.count() %}
      <div id="related-documents">
        <header>{{ _('See also:') }}</header>
        <ul>
          {% for related in document.related_documents.all() %}
            <li><a href="{{ url('wiki.document', related.slug) }}">{{ related.title }}</a></li>
          {% endfor %}
        </ul>
      </div>
    {% endif %}
  </article>
{% endblock %}
